mod test {
use hamcrest::{assert_that, equal_to, contains};
- use core::source::{SourceId, RegistryKind, Location, Remote};
+ use core::source::{SourceId, RegistryKind, GitKind, Location, Remote};
use core::{Dependency, PackageId, Summary, Registry};
use util::CargoResult;
PackageId::new(name, "1.0.0", ®istry_loc()).unwrap()
}
+ fn pkg_id_loc(name: &str, loc: &str) -> PackageId {
+ let remote = Location::parse(loc);
+ let source_id = SourceId::new(GitKind("master".to_str()),
+ remote.unwrap());
+
+ PackageId::new(name, "1.0.0", &source_id).unwrap()
+ }
+
+ fn pkg_loc(name: &str, loc: &str) -> Summary {
+ Summary::new(&pkg_id_loc(name, loc), &[])
+ }
+
fn dep(name: &str) -> Dependency {
let url = from_str("http://example.com").unwrap();
let source_id = SourceId::new(RegistryKind, Remote(url));
Dependency::parse(name, Some("1.0.0"), &source_id).unwrap()
}
+ fn dep_loc(name: &str, location: &str) -> Dependency {
+ let url = from_str(location).unwrap();
+ let source_id = SourceId::new(GitKind("master".to_str()), Remote(url));
+ Dependency::parse(name, Some("1.0.0"), &source_id).unwrap()
+ }
+
fn registry(pkgs: Vec<Summary>) -> Vec<Summary> {
pkgs
}
.collect()
}
+ fn loc_names(names: &[(&'static str, &'static str)]) -> Vec<PackageId> {
+ names.iter()
+ .map(|&(name, loc)| pkg_id_loc(name, loc)).collect()
+ }
+
#[test]
pub fn test_resolving_empty_dependency_list() {
let res = resolve(&pkg_id("root"), [], &mut registry(vec!())).unwrap();
assert_that(&res, contains(names(["root", "foo", "bar"])));
}
+ #[test]
+ pub fn test_resolving_with_same_name() {
+ let list = vec!(pkg_loc("foo", "http://first.example.com"),
+ pkg_loc("foo", "http://second.example.com"));
+
+ let mut reg = registry(list);
+ let res = resolve(&pkg_id("root"),
+ [dep_loc("foo", "http://first.example.com"),
+ dep_loc("foo", "http://second.example.com")],
+ &mut reg);
+
+ let mut names = loc_names([("foo", "http://first.example.com"),
+ ("foo", "http://second.example.com")]);
+
+ names.push(pkg_id("root"));
+
+ assert_that(&res.unwrap(), contains(names).exactly());
+ }
+
#[test]
pub fn test_resolving_with_dev_deps() {
let mut reg = registry(vec!(